package com.trkj.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.trkj.dao.MemberDAO;
import com.trkj.dao.MemberDAOFactory;
import com.trkj.entity.Member;

/**
 * Servlet implementation class MemberListServlet
 */
@WebServlet("/member_list")
public class MemberListServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private MemberDAO memberDAO = MemberDAOFactory.createDAO();

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, 
			HttpServletResponse response) throws ServletException, IOException {
		//获取请求参数
		int curpage = Integer.parseInt(
				request.getParameter("curpage"));
		int pagesize = Integer.parseInt(
				request.getParameter("pagesize"));
		
		//调用dao方法 
		List<Member> list = memberDAO
				.queryByPage(curpage, pagesize);
		int total = memberDAO.count();
		
		//将数据保存到作用域对象
		request.setAttribute("list", list);
		request.setAttribute("total", total);
		
		//转发
		request.getRequestDispatcher("main.jsp")
			.forward(request, response);
	}

}
